package edu.nepu.flink.api.source;


import org.apache.flink.api.common.eventtime.WatermarkStrategy;
import org.apache.flink.api.common.typeinfo.TypeInformation;
import org.apache.flink.api.connector.source.util.ratelimit.RateLimiterStrategy;
import org.apache.flink.configuration.Configuration;
import org.apache.flink.connector.datagen.source.DataGeneratorSource;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.streaming.api.functions.source.datagen.DataGenerator;

/**
 * @Date 2024/2/28 9:42
 * @Created by chenshuaijun
 */
public class MyDataGenSource {

    public static void main(String[] args) throws Exception {

        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(new Configuration());

        env.setParallelism(1);

        DataGeneratorSource<String> generatorSource = new DataGeneratorSource<>(
                index -> "number :" + index, // 生成的数据的形状
                1000,                       // 生成数据的条数
                RateLimiterStrategy.perSecond(10), // 每秒生成多少条数据
                TypeInformation.of(String.class)   // 生成的数据的类型
        );

        DataStreamSource<String> streamSource = env.fromSource(generatorSource, WatermarkStrategy.noWatermarks(), "data-gen-source");

        streamSource.print();

        env.execute();


    }
}
